// JavaScript Document
//  var path = window.location.pathname.split('/');
  var current_page;
  
  $.urlParam = function(name){
    var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
    if(results)
        return results[1] || 0;
}
  

$(document).ready(function(){
			
	/*$('<div>')                      // Creates the element
    .attr('id','mask')
    .html('Loading....')         // Sets the inner HTML to {hostname}
    .appendTo('body') ;*/
	 
           
           
           
	//$("#info-tabs").hide();	
	//$("#v-info-control-bar").hide();	
	//$("#vehicle-content-info").hide();
	//$('#info_mod_panel').hide();
	/*$('li').click(function(){
		
		$('li').removeClass('inactive').addClass('active');
		$('li').not(this).removeClass('active').addClass('inactive');
	});*/
	
	//$('div.page-list').show();
	//$('div.page-map').hide();
	//$('div.locked-content').hide();
	//$('div.forum-content').hide();
	
	
	$('#forums').click(function(){
		
		$('div.page-list').hide();
		$('div.page-map').hide();
		$('div.locked-content').hide();
		$('div.forum-content').show();
		$('#v-control-panel').hide();
		
	});
	
	//select all the a tag with name equal to modal
	

	$('a[name=modal]').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();
		
		//Get the A tag
		var id = $(this).attr('href');
	
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		//Set the popup window to center
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);
	
		//transition effect
		$(id).fadeIn(2000); 
	
	});
	
	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		$('#mask').hide();
		$('.window').hide();
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});	
			

	$(window).resize(function () {
	 
 		var box = $('#boxes .window');
 
        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();
      
        //Set height and width to mask to fill up the whole screen
        $('#mask').css({'width':maskWidth,'height':maskHeight});
        //$('#mask_2').css({'width':maskWidth,'height':maskHeight});  
        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();

        //Set the popup window to center
        box.css('top',  winH/2 - box.height()/2);
        box.css('left', winW/2 - box.width()/2);
	 
	});
	launchWelcomeWindow('#dialog');
});

function closeLuncher()
{
	$('#mask_2').hide();
	$('.window').hide();
}

function launchLoaderWindow(id) {
	
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(document).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$('#mask_2').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		$('#mask_2').fadeIn(500);	
		$('#mask_2').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		//Set the popup window to center
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);
	
		//transition effect
		$(id).fadeIn(500); 
		$(window).resize;
}

function launchWelcomeWindow(id) {
	
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(document).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		//Set the popup window to center
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);
	
		//transition effect
		$(id).fadeIn(2000); 
		$(window).resize;
}

function selectTabHandler(num){
	$('div.page-list').show();
	$('div.page-map').hide();
	$('div.locked-content').hide();
	$('div.forum-content').hide();
	$('#v-control-panel').show();
	$('#vehicle-list-header').show();
	$('#v-scroll-header').show();
}

function showInfoPage(){
	alert('ss');
}

function checkExtension(filePath)
		{
			if(filePath.indexOf('.') == -1)
				return false;
			
	
			var validExtensions = new Array();
			var ext = filePath.substring(filePath.lastIndexOf('.') + 1).toLowerCase();
		
			validExtensions[0] = 'jpg';
			validExtensions[1] = 'jpeg';
			validExtensions[2] = 'png';
			validExtensions[3] = 'pdf';
		
	
			for(var i = 0; i < validExtensions.length; i++) {
				if(ext == validExtensions[i])
					return true;
			}
	
			return false;
		}
		
		function makeupload() 
		{
			var files = $('input[type="file"]')[0].files;
			var checkResult ;
			
			for (var i = 0; i < files.length; i++)
			{
				 checkResult = checkExtension(files[i].name);
				 if(!checkResult)
				 {
					alert("Please ensure the file extensions as given below \n jpg, jpeg, png, pdf") ;
					return;
				 }
			} 
			
			if(imageCount<13)
			{
				document.getElementById('upload').target = 'upload_target';
				
				if(data1.vehicle.vehicle_id)
				{
					document.upload.action = 'php/process.php?vid='+ data1.vehicle.vehicle_id;
					document.upload.submit();
					imageCount = imageCount + files.length;
				}
			}
			else
			{
				alert('Your upload limit reached!!!');
			}
			
			
		}
		
		function removeByIndex(arrayName,arrayIndex)
		{ 
			arrayName.splice(arrayIndex,1); 
		}
